#include <stdio.h>

#define STDIN
//#define DEBUG

#define MAX 100000000

int N;
int array[101];
int c[101][101];//c[i][j] 表示[i:j]片断的最小分数

int compute(int i, int k, int j)
{
    if (i == k || k == j || i == j)
        return 0;
    else
        return array[i] * array[k] * array[j];
    return 0;
}

void find_min_score()
{
    int i, j, k;
#ifdef DEBUG
    for (i = 0; i < N; ++i)
        printf("%d\t", array[i]);
    printf("\n");
#endif

    for (i = 0; i < N-2; ++i)
    {
        c[i][i+2] = array[i] * array[i+1] * array[i+2];
    }

#ifdef DEBUG
    printf("=================:\n");
    for (i = 0; i < N; ++i)
    {
        for (j = 0; j < N ; ++j)
        {
            printf("%d\t", c[i][j]);
        }
        printf("\n");
    }
    printf("=================:\n");
#endif

    for (j = 2; j < N; ++j)
    {
        for (i = j - 2; i >= 0; --i)
        {
            int tmp = MAX;
            for (k = j-1; k >= i+1; k--)
            {
#ifdef DEBUG
                printf("i: %d k: %d j: %d\n", i, k, j);
#endif
                if (tmp > c[i][k] + c[k][j] + compute(i, k, j))
                        tmp = c[i][k] + c[k][j] + compute(i, k, j);
            }
            c[i][j] = tmp;
        }
    }

#ifdef DEBUG
    printf("=================:\n");
    for (i = 0; i < N; ++i)
    {
        for (j = 0; j < N ; ++j)
        {
            printf("%d\t", c[i][j]);
        }
        printf("\n");
    }
    printf("=================:\n");
#endif

    printf("%d\n", c[0][N-1]);
}

int main()
{
#ifdef STDIN
    freopen("bin/1651.in", "r", stdin);
#endif

    scanf("%d", &N);

    int i;
    for (i = 0; i < N; ++i)
    {
        scanf("%d", &array[i]);
    }

    find_min_score();
    return 0;
}
